package com.zabra.zl.ui.mybank.presenter;

import com.zabra.zl.base.BasePresenter;
import com.zabra.zl.data.BankListBean;
import com.zabra.zl.ui.mybank.contract.MyBankContract;
import com.zabra.zl.ui.mybank.model.MyBankModel;

import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MyBankPresenter extends BasePresenter<MyBankContract.View> implements MyBankContract.Presenter {
    private MyBankContract.Model model;
    public MyBankPresenter() {
        model=new MyBankModel();
    }

    @Override
    public void getData(RequestBody body) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getData(body).enqueue(new Callback<BankListBean>() {
            @Override
            public void onResponse(Call<BankListBean> call, Response<BankListBean> response) {
                mView.hideLoading();
                mView.onSuccess(response.body(),response.headers().get("token"));
            }

            @Override
            public void onFailure(Call<BankListBean> call, Throwable t) {
                mView.hideLoading();
                mView.onError(t);
            }
        });
    }
}
